//MyAdvice.java
package org.example.demo3.spring;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

//定义前置增强类
public class MyAdvice implements MethodBeforeAdvice, AfterReturningAdvice, MethodInterceptor {

    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("Method Before: " + method.getName());
        System.out.println("这是我的前置增强");
    }


    @Override
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("After method: " + method.getName());
        System.out.println("这是我的后置增强");
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("环绕增强开始");
        Object result = invocation.proceed();
        System.out.println("环绕增强结束");
        return result;
    }
}
